﻿#ifndef DESCRIPTION_H
#define DESCRIPTION_H

#include <QObject>
#include <QXmlStreamWriter>
#include "device.h"
#include "objectfactory.h"
#include "sequence.h"
#include <QThread>
#include <QCoreApplication>
#include <QJsonObject>
#include <QJsonArray>


class Description;

class Description : public QObject
{
    Q_OBJECT
public:
    Description();
    ~Description(){
    }

    Description& operator=(Description& description);

private:
    QList<Device *>     m_pDevices;
    QList<Sequence *>   m_pSequences;
    bool                m_isAllInitialized;
    bool                m_isRunning;

    void                InitObjectFactory();

public:
    Device              *FindDeviceById(QString strID);
    QList<Sequence *>   GetSequences(){return m_pSequences;}
    QList<Device *>     GetDevices(){return m_pDevices;}
    void                SetAllInitialized(bool isInitialized){m_isAllInitialized = isInitialized;}
    void                RemoveDevice(int index){Device * pDevice = m_pDevices.at(index);delete pDevice;m_pDevices.removeAt(index);}
    void                RemoveSequence(int index){m_pSequences.removeAt(index);}
    Step*               GetStepByImageNum(int number);

public:
    void clear();

public:
    void AddDevice(Device *pDevice) { m_pDevices.append(pDevice); }
    void AddSequence(Sequence *pSequence) { m_pSequences.append(pSequence); }

public:
    bool writeXML(const QString &filePath);
    bool ReadXML(const QString &filePath);

    bool writeXML(QXmlStreamWriter &xmlWriter);
    bool ReadXML(QXmlStreamReader &xmlReader);

    void initAllDevices();
    void uninitAllDevices();
    void run();
    void stop();
    void test();
    QList<Device *> pDevices() const;
    QList<Sequence *> pSequences() const;

private:
    //DescriptionRunThread *m_DescriptionRunThread;

public slots:
    // 接收到虚拟设备的命令
    void ReceviceCmdFromVirtualDevice(QVariant variant);

signals:
    void SendCmdToMainWindow(QVariant variant);
};

#endif // DESCRIPTION_H
